 # -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User
# Create your models here.

class Type(models.Model):
    types=models.CharField(max_length=15)
    def __unicode__(self):
        return self.types
class Tag(models.Model):
    tags=models.CharField(max_length=15)
    def __unicode__(self):
        return self.tags
class Questions(models.Model):
    question=models.CharField(max_length=10)
    abstract=models.TextField()
    view_count=models.IntegerField(default=0)
    agree_count=models.IntegerField(default=0)
    against_count=models.IntegerField(default=0)
    submit_time=models.DateTimeField(auto_now_add=True)
    state=models.SmallIntegerField(default=0)
    sub_user=models.ForeignKey(User)
    type=models.ForeignKey(Type,on_delete=models.CASCADE)
    tag=models.ForeignKey(Tag,on_delete=models.CASCADE)
    def __unicode__(self):
        return self.question
    class Meta:
        db_table='question'
        managed=True
class Answer(models.Model):
    content=models.TextField()
    zan_count=models.IntegerField(default=0)
    ans_time=models.DateTimeField(auto_now_add=True)
    ans_user=models.ForeignKey(User)
    ans_question=models.ForeignKey(Questions,on_delete=models.CASCADE)
    def __unicode__(self):
        return self.content

